﻿using System;
using Windows.ApplicationModel.Resources;
using Windows.UI;
using Windows.UI.ViewManagement;

namespace BuddyTracker.ViewModel.Helpers
{
    /// <summary>
    /// Helper class for managing Windows Phone status bar.
    /// </summary>
    static class StatusBarHelper
    {
        /// <summary>
        /// Shows an indeterminate status bar (loading dots).
        /// </summary>
        public static async void ShowIndeterminate()
        {
            StatusBar statusBar = StatusBar.GetForCurrentView();
            statusBar.ProgressIndicator.ProgressValue = null;
            await statusBar.ProgressIndicator.ShowAsync();
        }

        /// <summary>
        /// Hides any status bar and resets it to default.
        /// </summary>
        public static async void Hide()
        {
            StatusBar statusBar = StatusBar.GetForCurrentView();
            statusBar.ProgressIndicator.ProgressValue = null;
            statusBar.BackgroundColor = Colors.Transparent;
            statusBar.BackgroundOpacity = 0;
            statusBar.ProgressIndicator.Text = string.Empty;
            await statusBar.ProgressIndicator.HideAsync();
        }

        /// <summary>
        /// Shows twitter blue status bar with enter pin message.
        /// </summary>
        public static async void ShowForTwitter()
        {
            StatusBar statusBar = StatusBar.GetForCurrentView();
            statusBar.ProgressIndicator.Text = new ResourceLoader().GetString("TwitterPINMessage");
            statusBar.ProgressIndicator.ProgressValue = 0;
            statusBar.BackgroundColor = Color.FromArgb(255, 29, 202, 255); //twitter blue
            statusBar.BackgroundOpacity = 1; // zero transparent
            await statusBar.ProgressIndicator.ShowAsync();
        }
    }
}
